<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <main id="app">
        <p ref="my-p">{{fullName}}</p>
        <button @click="firstName = '先'">点击我</button>
    </main>
</body>
<script src="../vue.js"></script>
<script>


    new Vue({
        el: "#app",
        data() {
            return {
                firstName: "Hydra",
                lastName: "Feng"
            }
        },
        computed: {
            fullName() {
                return `${this.firstName} ${this.lastName}`
            }
        },
        beforeCreate() {
            console.log("------------beforeCreate---------------");
            console.log("this = ",this);
            console.log("this.$el = ",this.$el); // undefined
            console.log("this.$data = ",this.$data); // undefined
        },
        created() {
            console.log("------------created---------------");
            console.log("this.$el = ",this.$el); // undefined
            console.log("this.$data = ",this.$data); // 有数据
            console.log("this.fullName = ",this.fullName); // 有数据

            this.$nextTick(() => {
                console.log("nextTick执行：",this.$refs["my-p"].innerText);
            })
        },
        beforeMount() {
            console.log("------------beforeMount---------------");
            console.log("this.$el = ",this.$el); // 有数据
            console.log("this.$el.innerText = ",this.$el.innerText); // {{fullName}}
        },
        mounted() {
            console.log("------------mounted---------------");
            console.log("this.$el = ",this.$el); // 有数据
            // mounted是最早可以操作DOM节点的生命周期函数
            console.log("my-p.innerText = ",this.$refs["my-p"].innerText); // Hydra Feng

           
        },
        beforeUpdate() {
            console.log("------------beforeUpdate---------------");
            console.log("this.$el = ",this.$el); // 有数据
            console.log("my-p.innerText = ",this.$refs["my-p"].innerText); // Hydra Feng
        },
        updated() {
            console.log("------------updated---------------");
            console.log("this.$el = ",this.$el); // 有数据
            console.log("my-p.innerText = ",this.$refs["my-p"].innerText); // Hydra Feng
        },
        beforeDestory() {
            console.log("------------beforeDestory---------------");
            console.log("this.$el = ",this.$el); 
            console.log("this.$data = ",this.$data); 
        },
        destoryed() {
            console.log("------------destoryed---------------");
            console.log("this.$el = ",this.$el); 
            console.log("this.$data = ",this.$data); 
        }
    })
</script>
</html>